<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>卡列表</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>

    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="../../resource/css/plugins/morris/morris-0.4.3.min.css"
          th:href="@{/resource/css/plugins/morris/morris-0.4.3.min.css}" rel="stylesheet">

    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>

    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">

    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>

    <link href="../../resource/hotui/css/switchery.min.css"
          th:href="@{/resource/hotui/css/switchery.min.css}" rel="stylesheet"/>

    <link href="../../resource/lib/bootstrap-daterangepicker/daterangepicker.min.css"
          th:href="@{/resource/lib/bootstrap-daterangepicker/daterangepicker.min.css}" rel="stylesheet">

    <link href="../../resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css"
          th:href="@{/resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css}" rel="stylesheet"/>

    <link href="../../resource/hotui/css/awesome-bootstrap-checkbox.min.css"
          th:href="@{/resource/hotui/css/awesome-bootstrap-checkbox.min.css}"
          rel="stylesheet">

    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }

        .city-picker-selector select {

        }

        .nav-tabs input {
            width: 20px;
            height: 23px;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${status}" name="status"/>
                            <input type="hidden" th:value="${voltageStatus}" name="voltageStatus"/>
                            <input type="hidden" th:value="${dismantleStatus}" name="dismantleStatus"/>
                            <input type="hidden" th:value="${onlineStatus}" name="onlineStatus"/>
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <div class="form-group m-r-sm">
                                <label class="control-label">定位器编号：</label>
                                <input type="text" class="form-control input-sm mb10" id="no" name="no"
                                       th:value="*{no}"
                                       placeholder="请输入完整卡号"/>
                                <label class="control-label">定位器类型：</label>
                                <select class="form-control" name="type" id="type">
                                    <option value="-1">全部</option>
                                    <option th:selected="*{type==2}" value="2">室外定位器</option>
                                    <option th:selected="*{type==3}" value="3">室内定位器</option>
                                </select>

                            </div>
                            <div style="float: right;">
                                <button type="button" class="btn btn-success" onclick="jsHelper.search()">筛选</button>
                                <button type="button" class="btn btn-success" onclick="jsHelper.searchAll()">显示全部
                                </button>
                                <button type="button" class="btn btn-success" onclick="jsHelper.setCard()">添加</button>
                                <button type="button" onclick="jsHelper.uploadUpdateExcelModal()"
                                        class="btn btn-success">导入
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->

    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active"
                            th:class="${(condition.status==null&&condition.voltageStatus==null
                            &&condition.dismantleStatus==null&&condition.onlineStatus==null)?'active':''}">
                            <a th:href="@{/equipment/locator/list}" href="#tab-2">全部</a>
                        </li>
                        <li th:class="${condition.status==true?'active':''}">
                            <a th:href="@{/equipment/locator/list(status=true)}">
                                报警</a>
                        </li>
                        <li th:class="${condition.voltageStatus==1?'active':''}">
                            <a th:href="@{/equipment/locator/list(voltageStatus=1)}">
                                低电压</a>
                        </li>
                        <li th:class="${condition.onlineStatus==false?'active':''}">
                            <a th:href="@{/equipment/locator/list(onlineStatus=0)}">
                                离线</a>
                        </li>
                        <li th:class="${condition.dismantleStatus==false?'active':''}">
                            <a th:href="@{/equipment/locator/list(dismantleStatus=0)}">
                                拆卸异常</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body">
                                <div class="form-group" style="float: right;">
                                    <button type="button" onclick="jsHelper.addToArea()"
                                            class="btn btn-primary btn-sm">添加到区域
                                    </button>
                                    <button type="button" onclick="jsHelper.areaManage()"
                                            class="btn btn-primary btn-sm">区域管理
                                    </button>
                                </div>

                                <table class="table table-bordered table-hover table-center">
                                    <tr>
                                        <th>
                                            <div class="checkbox checkbox-primary"
                                                 style="padding-left: 15px;margin-right: -10px">
                                                <input type="checkbox" id="chkAll"/>
                                                <label for="chkAll"> </label>
                                            </div>
                                        </th>
                                        <th>定位器编号</th>
                                        <th>定位器类型</th>
                                        <th>设备版本</th>
                                        <th>区域</th>
                                        <th>是否节点</th>
                                        <th>描述</th>
                                        <th>在线状态</th>
                                        <th>报警状态</th>
                                        <th>电压状态</th>
                                        <th>防拆卸状态</th>
                                        <th>启用状态</th>
                                        <th>操作</th>
                                    </tr>
                                    <tr th:each="locator,index:${locators}">
                                        <td>
                                            <div class="checkbox checkbox-primary"
                                                 style="padding-left: 15px;margin-right: -10px">
                                                <input type="checkbox" id="chk_1" name="chkItem"
                                                       th:value="${locator.locatorId}"
                                                       th:id="${'chk_'+locator.locatorId}"/>
                                                <label for="chk_1" th:for="${'chk_'+locator.locatorId}"> </label>
                                            </div>
                                        </td>
                                        <td th:text="${locator.no}"></td>
                                        <td>
                                            <span th:text="${locator.type.desc}"></span>
                                        </td>
                                        <td>
                                            <span th:text="${locator.version}"></span>
                                        </td>
                                        <td th:text="${locator.areaPO==null?'':locator.areaPO.name}"></td>
                                        <td>
                                            <span th:text="${locator.locatorInfo.floorNode?'是':'否'}"></span>
                                        </td>
                                        <td>
                                            <span th:text="${locator.describe}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${locator.getOnlineStyle()}"
                                                  th:text="${locator.onlineStatus?'在线':'离线'}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${locator.getStatusStyle()}"
                                                  th:text="${locator.status?'报警':'未报警'}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${locator.getVoltageStatusStyle()}"
                                                  th:text="${locator.voltageStatus.desc}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${locator.getDismantleStatusStyle()}"
                                                  th:text="${locator.dismantleStatus?'正常':'异常'}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${locator.getEnableStyle()}"
                                                  th:text="${locator.enable?'启用':'禁用'}"></span>
                                        </td>

                                        <td>
                                            <button th:onclick="jsHelper.setCard([[${locator.locatorId}]],[[${locator.no}]],[[${locator.type.code}]],[[${locator.version}]],[[${locator.locatorInfo.floorNode}]],[[${locator.describe}]],[[${locator.alarmedImmediately?1:0}]],[[${locator.alarmTemplate}]])"
                                                    type="button"
                                                    class="btn btn-info btn-xs m-b-none">编辑
                                            </button>
                                            <button th:onclick="|jsHelper.delete(${locator.no})|"
                                                    type="button"
                                                    class="btn btn-default btn-xs m-b-none">删除
                                            </button>
                                            <button onclick="jsHelper.setEnable(1)"
                                                    th:onclick="|jsHelper.setEnable(${locator.locatorId})|"
                                                    type="button"
                                                    class="btn btn-info btn-xs m-b-none"
                                                    th:class="${locator.enable?'btn btn-danger btn-xs m-b-none':'btn btn-info btn-xs m-b-none'}"
                                                    th:text="${locator.enable?'禁用':'启用'}">
                                            </button>
                                            <!--<button onclick="jsHelper.setDir(1)"-->
                                            <!--th:onclick="|jsHelper.setDir(${locator.locatorId})|" type="button"-->
                                            <!--class="btn btn-info btn-xs m-b-none"-->
                                            <!--th:class="${locator.dismantleStatus?'btn btn-danger btn-xs m-b-none':'btn btn-info btn-xs m-b-none'}"-->
                                            <!--th:text="${locator.dismantleStatus?'拆卸异常':'拆卸修复'}">-->
                                            <!--</button>-->
                                        </td>
                                    </tr>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="set_card_modal" class="modal-content-tag">
    <div class="form-horizontal" style="width: 600px;">
        <form id="cardModelForm">
            <div class="form-group">
                <label class="col-sm-3 control-label">定位器编号：</label>
                <div class="col-sm-9">
                    <input id="modelId" name="modelId" minlength="2" type="hidden" class="form-control"
                           value="0">
                    <input id="modelNo" type="text" class="form-control" name="modelNo">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">定位器版本：</label>
                <div class="col-sm-9">
                    <input id="modelVersion" type="text" class="form-control" name="modelVersion">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-9">
                    <input id="desc" type="text" class="form-control" name="modelVersion">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">定位器类型：</label>
                <div class="col-sm-9">
                    <select class="form-control" name="modelType" id="modelType">
                        <option th:selected="*{type==2}" value="2">室外定位器</option>
                        <option th:selected="*{type==3}" value="3">室内定位器</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否节点：</label>
                <div class="col-sm-9">
                    <select class="form-control" name="modelFloorNode" id="modelFloorNode">
                        <option th:selected="*{floorNode==0}" value="0">否</option>
                        <option th:selected="*{floorNode==1}" value="1">是</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">特定住户立即警报：</label>
                <div class="col-sm-9">
                    <select class="form-control" name="modal_alarmedImmediately" id="modal_alarmedImmediately">
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">警报模板：</label>
                <div class="col-sm-9">
                    <input id="modal_alarmTemplate" type="text" class="form-control" name="modal_alarmTemplate">
                </div>
            </div>
        </form>
    </div>
</div>

<div id="uploadExcel_modal" class="modal-content-tag">
    <div class="form-horizontal" style="width: 479px;">
        <div class="form-group form-inline">
            <label class="col-sm-4 control-label">选择excel：</label>
            <div class="col-sm-8">
                <button class="btn btn-success  dim" type="button" onclick="javascript:$('#updateFile').click()"><i
                        class="fa fa-upload">选择文件</i>
                </button>
                <span class="col-sm-8" style="display: none">文件名称</span>
                <input type="file" name="updateFile" id="updateFile" accept="application/vnd.ms-excel" required
                       style="display: none">
            </div>
        </div>
    </div>
</div>

<script id="select_area_modal" type="text/html">
    <div class="ibox float-e-margins" style="width: 500px;">
        <div class="ibox-content" style="border-top: none;">
            <div class="panel-body form-horizontal">
                <input type="hidden" id="sel_items"/>
                <div class="form-group form-inline">
                    <label class="col-sm-3 control-label">区域:</label>

                    <div class="col-sm-9">
                        <select class="form-control input-sm mb10" id="sel_area">
                            <option th:each="item:${areaList}" th:value="${item.id}" th:text="${item.name}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>
</script>

<!--基础框架js-->
<script src="../../resource/js/jquery.min.js" th:src="@{/resource/js/jquery.min.js?20190316}"></script>
<script src="../../resource/js/bootstrap.min.js" th:src="@{/resource/js/bootstrap.min.js?20190316}"></script>


<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316?1234567"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316(123)}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="../../resource/hotui/js/plugins/datetimepick/js/moment.min.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/moment.min.js}"></script>

<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>

<script src="../../resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js}"></script>
<script src="../../resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js}"></script>

<script src="../../resource/js/switchery.min.js" th:src="@{/resource/js/switchery.min.js}"></script>

<script src="../../resource/js/plugins/validate/jquery.validate.min.js"
        th:src="@{/resource/js/plugins/validate/jquery.validate.min.js}"></script>

<script src="../../resource/js/plugins/validate/messages_zh.min.js"
        th:src="@{/resource/js/plugins/validate/messages_zh.min.js}"></script>

<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-validate.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-validate.js}"></script>


<script src="../../resource/hotui/plugins/zyUpload/core/zyFile.js"></script>
<script src="../../resource/hotui/plugins/zyUpload/control/js/zyUpload.js"></script>
<script src="../../resource/hotui/js/plugins/ajaxfileupload.js"
        th:src="@{/resource/hotui/js/plugins/ajaxfileupload.js}"></script>


<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/equipment/locator/list}]]*/  "";
    const equipmentApiBase = /*[[@{/equipment}]]*/  "/equipment";
    const areaManageUri = /*[[@{/locator/area/list}]]*/  "locator_area_list.html";
</script>

<script>
    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            jsHelper.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                $(".searchBtn").trigger("click");
            }
        });

        $("#chkAll").change(function () {
            if ($(this).prop("checked")) {
                $("input[name=chkItem]").prop("checked", "checked");
            } else {
                $("input[name=chkItem]").removeAttr("checked");
            }
        });
        jsHelper.init();
    });

    var selAreaModal = $("#select_area_modal").modal("请选择区域", function () {
        let items = $("#sel_items").val();
        let area = $("#sel_area").val();

        let requestData = {
            areaId: area,
            ids: items
        };
        hot.ajax(equipmentApiBase + "/locator/addToArea", requestData, function (apiResult) {
            if (apiResult.resultCode === 2000) {
                hot.tip.success("操作成功", function () {
                    window.location.reload();
                });
            } else {
                hot.tip.error("操作失败--" + apiResult.resultMsg);
            }
        }, function () {
        }, "post", 300);
    });

    var setCardModel = $("#set_card_modal").modal("定位器信息", function () {
        $("#cardModelForm").submit();
    });

    var uploadExcelModal = $("#uploadExcel_modal").modal("定位器excel导入", function () {
        jsHelper.uploadExcel();
    });

    var jsHelper = {
        init: function () {
        },
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        /**
         * 修改状态
         * @param dataId
         */
        setEnable: function (dataId) {
            hot.ajax("/equipment/edit/locator/enable", {
                locatorId: dataId
            }, function (ret) {
                if (ret.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败-" + ret.resultMsg);
                }
            }, function () {
            }, "post");
        },
        delete: function (no) {
            hot.confirm("确定删除定位器" + no + "吗？", function () {
                hot.ajax("/equipment/delete/locator", {
                    no: no
                }, function (ret) {
                    if (ret.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        })
                    } else {
                        hot.tip.error("操作失败-" + ret.resultMsg);
                    }
                }, function () {
                }, "post");
            })
        },
        setDir: function (dataId) {
            hot.ajax("/equipment/edit/locator/dismantle", {
                locatorId: dataId
            }, function (ret) {
                if (ret.resultCode === 2000) {
                    hot.tip.success("成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败-" + ret.resultMsg);
                }
            }, function () {
            }, "post");
        },
        setCard: function (id, no, type, version, floorNode, describe, alarmedImmediately, alarmTemplate) {
            setCardModel.show(function () {
                if (id != null) {
                    $("#modelId").val(id);
                    $("#modelNo").val(no);
                    $("#modelType").val(type);
                    $("#modelVersion").val(version);
                    $("#modelFloorNode").val(floorNode ? 1 : 0);
                    $("#desc").val(describe);
                    $("#modal_alarmedImmediately").val(alarmedImmediately);
                    $("#modal_alarmTemplate").val(alarmTemplate);
                }
                $("#cardModelForm").validateCallback(function () {
                    var requestData = {
                        locatorId: $("#modelId").val(),
                        no: $("#modelNo").val(),
                        type: $("#modelType").val(),
                        version: $("#modelVersion").val(),
                        floorNode: $("#modelFloorNode").val(),
                        describe: $("#desc").val(),
                        alarmedImmediately: $("#modal_alarmedImmediately").val(),
                        alarmTemplate: $("#modal_alarmTemplate").val()
                    };

                    hot.ajax(equipmentApiBase + "/ajax/save/locator", requestData, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            setCardModel.hide(function () {
                                hot.tip.success("设置成功");
                                window.location.reload();
                            });
                        } else {
                            hot.tip.error("设置失败--" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post", 300);
                })
            });
        },
        uploadUpdateExcelModal: function () {
            uploadExcelModal.show(function () {
                $("#updateFile").change(function () {
                    $("#updateFile").prev().css("display", "");
                    var filePath = $("#updateFile").val().split("\\");
                    $("#updateFile").prev().text(filePath[filePath.length - 1]);
                })
            });
        },
        uploadExcel: function () {
            hot.managerFileUpload(equipmentApiBase + "/lead/locator", "updateFile", null, function (data) {
                if (data == 1) {
                    window.location.reload();
                }
            });
        },
        areaManage: function () {
            hot.iframeModal(areaManageUri, window.innerWidth * 0.7 + "px", window.innerHeight * 0.75 + "px", '区域管理')
        },
        addToArea: function () {
            let $chkItems = $("input[name=chkItem]:checked");
            if ($chkItems.length === 0) {
                hot.tip.msg("请勾选要加入的定位器");
                return;
            }

            let items = "";
            $chkItems.each(function () {
                items += $(this).val() + ",";
            });
            items = items.substring(0, items.length - 1);

            selAreaModal.show(function () {
                $("#sel_items").val(items);
            });
        }
    };
</script>
</body>
</html>
